package com.wuba.rxjavademo.tzx.merge;

import com.wuba.rxjavademo.tzx.common.Base;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by tanzhenxing
 * Date: 2016/6/28.
 * Description:
 * zip()合并两个或者多个Observables发射出的数据项，根据指定的函数Func*变换它们，并发射一个新值
 */
public class RxZip extends Base {
    public static void main(String[] args) {
        RxZip rxZip = new RxZip();
        rxZip.run();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        Observable<Long> tictoc = Observable.interval(1, TimeUnit.MILLISECONDS);
        Observable.zip(getObservable(), tictoc, (Integer sum, Long time) -> sum*time)
                .subscribe(Base::print);

    }
}
